package com.panopset;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;

public class HttpCOPYclient {

    final HttpGETclient c;

    public HttpCOPYclient(URL newURL) {
        c = new HttpGETclient(newURL);
    }

    public void copy(final File f) {
        f.getParentFile().mkdirs();
        try (InputStreamReader isr = new InputStreamReader(c.getConnection()
                .getInputStream());
                BufferedReader br = new BufferedReader(isr);
                FileWriter fw = new FileWriter(f);
                BufferedWriter bw = new BufferedWriter(fw)) {
            int c = br.read();
            while (c != -1) {
                bw.write(c);
                c = br.read();
            }
        } catch (Exception ex) {
            Logger.log(ex);
        }
    }
}
